package com.hhxy.string;

import java.util.Random;

public class GenerateCaptcha {
    public static void main(String[] args) {
        System.out.println("随机生成的验证码为："+genrateCaptcha());
    }
    //随机生成验证码
    private static String genrateCaptcha() {
        Random r = new Random();
        String data = "QWETYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890";
        String captcha="";
        for (int i = 0; i <4 ; i++) {
            int index = r.nextInt(data.length());//随机返回一个data的索引号
            char c = data.charAt(index);
            captcha += c;
        }
        return captcha;
    }
}
